﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using System.Web;
using Antu.WorkFlowFactory;
using System.Data;
using System.Configuration;

namespace WebSys.UI.OfficeFlow
{
    public class InstanceSearchSkin : MPBasicTemplate
    {
        FlowFactoryProvider _FlowFactoryProvider = (FlowFactoryProvider)ProviderService.ProviderServiceMange.GetProvider("FlowFactoryProvider");
        TextBox iid, taskname, ajh,txtXMMC,txtZSJDH,txtFWZL,txtBZSR;
        Button search;
        string userid;
        DropDownList flowtype,ddlQH;
        MPCalendar startdate, enddate;
        CheckBox isComplete, notComplete;
        protected string UserId
        {
            get { if (base.Page.Session["UserId"] != null) { return base.Page.Session["UserId"].ToString(); } else { return string.Empty; } }
            set { base.Page.Session["UserId"] = value; }
        }
        protected override void OnLoad(EventArgs e)
        {
            LoginHelper.CheckLogin();
            InitControl();
			GetQuHua();//绑定行政区划下拉框
            base.OnLoad(e);
            if (!base.Page.IsPostBack)
            {
                Initcy();
            }
        }

        private void InitControl()
        {
            userid = UserId;
            flowtype = (DropDownList)FindControl("flowtype");
            iid = (TextBox)FindControl("iid");
            ajh = (TextBox)FindControl("ajh");
            taskname = (TextBox)FindControl("taskname");
            search = (Button)FindControl("search");
            search.Click += new EventHandler(search_Click);
            startdate = (MPCalendar)FindControl("startdate");
            enddate = (MPCalendar)FindControl("enddate");
            isComplete = (CheckBox)FindControl("isComplete");
            notComplete = (CheckBox)FindControl("notComplete");

			ddlQH = (DropDownList)FindControl("ddlQH");
			txtXMMC = (TextBox)FindControl("txtXMMC");
			txtZSJDH = (TextBox)FindControl("txtZSJDH");
			txtFWZL = (TextBox)FindControl("txtFWZL");
			txtBZSR = (TextBox)FindControl("txtBZSR");
        }

		//绑定行政区划下拉框
		public void GetQuHua()
		{
			string sql = @"select keyname from zs_params where name = '区属'";
			DataTable dt = _FlowFactoryProvider.GetOneDs("(" + sql + ")", "*", "").Tables[0];
			ddlQH.DataValueField = "keyname";
			ddlQH.DataTextField = "keyname";
			ddlQH.DataSource = dt;
			ddlQH.DataBind();
			ddlQH.Items.Insert(0, "所有");

		}

        private void search_Click(object sender, EventArgs e)
        {
            string ksdate = base.Page.Server.UrlEncode(startdate.Text);
            string jzdate = base.Page.Server.UrlEncode(enddate.Text);
            string isbj = (isComplete.Checked) ? "1" : "0";
            string notbj = (notComplete.Checked) ? "1" : "0";
			

            //string url = "InstanceSearch.aspx?action=instancesearchlist&iid=" + iid.Text + "&taskname=" + taskname.Text + "&flowtype=" + flowtype.SelectedValue;
            string url = "InstanceSearch.aspx?action=instancesearchlist&iid=" + iid.Text + "&taskname=" + taskname.Text + "&flowtype=" + flowtype.SelectedValue + "&ksdate=" + ksdate + "&jzdate=" + jzdate + "&isbj=" + isbj + "&notbj=" + notbj + "&qh="+ddlQH.SelectedValue+"&xmmc="+txtXMMC.Text+"&zsjdh="+txtZSJDH.Text+"&fwzl="+txtFWZL.Text+"&bzsr="+txtBZSR.Text;
            string OfficeUsers = System.Configuration.ConfigurationManager.AppSettings["OfficeSearch"].ToString();
            if (!string.IsNullOrEmpty(OfficeUsers)) 
            {
                if (OfficeUsers.IndexOf(userid) == 0)  
                {
                    url += "&ajh=" + ajh.Text.Trim();
                }
               
            }
            base.Page.Response.Redirect(url);
        }
        private void Initcy()
        {
            string ajlx = ConfigurationManager.AppSettings["ZSAnJianType"].ToString();
            DataTable dt = _FlowFactoryProvider.NewGetUserRightWname(UserId, ajlx);
            ListItem item = new ListItem("全部");
            List<ListItem> itemlist = new List<ListItem>();
            itemlist.Add(item);
            if (dt != null && dt.Rows.Count > 0)
            {
                for (int temp = 0; temp < dt.Rows.Count; temp++)
                {
                    item = new ListItem(dt.Rows[temp]["wname"].ToString());
                    itemlist.Add(item);
                }
                flowtype.DataSource = itemlist;
                flowtype.DataBind();
                string OfficeUsers = System.Configuration.ConfigurationManager.AppSettings["OfficeSearch"].ToString();
                if (!string.IsNullOrEmpty(OfficeUsers))
                {
                    if (OfficeUsers.IndexOf(userid) == 0)  
                    {
                        Antu.Utilities.UtilitiesPage.RegJsScript("displayone();");
                    }
                }
            }
            else
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("您没有任何流程查询权限！", "");
            }           

        }


    }
}


